﻿package mlc.haxe.input.command;

/**
 * A command that accepts any number of arguments, but does not format them.
 */
class RawCommand extends Command, implements ExecutableCommand {
	private var method:Array<String> -> Void;
	/**
	 * Creates a new raw command.
	 */
	public function new(method:Array<String> -> Void, remove:String -> Bool, key:String):Void {
		super(remove, key);
		this.method = method;
	}
	public function execute(arguments:Array<String>, writeError:String -> Void):Void {
		method(arguments);
	}
	public function determineEquals(value:ExecutableCommand):Bool {
		// Since the first check makes sure the type of the passed value is equal to this one, it is safe to assume that the passed
		// value has a method property in the second. However, AS3 compilers don't like this. We have to cast it explicitly for
		// them.
		#if as3
		return Std.is(value, RawCommand) && Reflect.compareMethods(cast(value, RawCommand).method, method);
		#else
		return Std.is(value, RawCommand) && Reflect.compareMethods((untyped value).method, method);
		#end
	}
}